﻿<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" CodeBehind="Default.aspx.cs"
    Inherits="Web.View.userMgr.Default" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>起点10--WebMisDeveloper后台用户管理</title>
    <script src="/View/js/Alert.js" type="text/javascript"></script>
    <script type="text/javascript">
        var GetRoleName = function (value) {
            index = S_Roles.find("roleid", value, 0, false, false);
            return S_Roles.getAt(index).get('rolename');
        } 
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager runat="server" />
    <ext:Hidden ID="GridData" runat="server" />
    <ext:Store runat="server" ID="S_Roles" OnRefreshData="GetAllRoles" AutoLoad="true">
        <Proxy>
            <ext:PageProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="roleid">
                <Fields>
                    <ext:RecordField Name="roleid" />
                    <ext:RecordField Name="rolename" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <Listeners>
            <Load Handler="#{cboRole}.setValue(#{S_Roles}.getAt(0).get('roleid'));" />
        </Listeners>
    </ext:Store>
    <ext:Store ID="Store1" runat="server" OnRefreshData="InfoBind" AutoLoad="true">
        <Proxy>
            <ext:PageProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="userid">
                <Fields>
                    <ext:RecordField Name="userid" />
                    <ext:RecordField Name="username" />
                    <ext:RecordField Name="password" />
                    <ext:RecordField Name="roleid" />
                    <ext:RecordField Name="telephone" />
                    <ext:RecordField Name="usersex" />
                    <ext:RecordField Name="address" />
                    <ext:RecordField Name="email" />
                    <ext:RecordField Name="logintime" />
                    <ext:RecordField Name="createtime" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <BaseParams>
            <ext:Parameter Name="start" Value="0" Mode="Raw">
            </ext:Parameter>
            <ext:Parameter Name="limit" Value="15" Mode="Raw">
            </ext:Parameter>
        </BaseParams>
    </ext:Store>
    <ext:Viewport ID="Viewport1" runat="server">
        <Items>
            <ext:FitLayout ID="FitLayout1" runat="server">
                <Items>
                    <ext:GridPanel ID="GridPanel1" Layout="fit" TrackMouseOver="true" runat="server"
                        StoreID="Store1" StripeRows="true" Header="false" Border="false" Collapsible="true">
                        <TopBar>
                            <ext:Toolbar ID="Toolbar1" runat="server">
                                <Items>
                                    <ext:Button ID="Button1" runat="server" Text="添加" Icon="Add">
                                        <Listeners>
                                            <Click Handler="#{WinUser}.show();#{RegistForm}.getForm().reset();#{cboRole}.setValue(#{cboRole}.store.getAt(0).get('roleid'));#{Hid}.setValue('');" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="BtnDel" runat="server" Text="删除" Icon="Delete">
                                        <DirectEvents>
                                            <Click OnEvent="BtnDel_Click">
                                                <Confirmation ConfirmRequest="true" Title="确认" Message="确实要删除吗?" />
                                                <EventMask ShowMask="true" Msg="正在删除数据，请等候 ..." />
                                            </Click>
                                        </DirectEvents>
                                        <Listeners>
                                            <Click Handler="if(#{GridPanel1}.getSelectionModel().getCount()<=0) {TellAlert('请选择要删除的记录');return false;}" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator ID="ToolbarSeparator3" runat="server" />
                                    <ext:Button ID="Button3" runat="server" Text="重新加载" Icon="Reload">
                                        <Listeners>
                                            <Click Handler="#{S_Roles}.reload();#{Store1}.reload();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                                    <ext:Button ID="Button4" runat="server" Text="To Excel" AutoPostBack="true" OnClick="SaveToExcel"
                                        Icon="PageExcel">
                                        <Listeners>
                                            <Click Handler="#{GridData}.setValue(Ext.encode(GridPanel1.getRowsValues(false)));" />
                                        </Listeners>
                                        <ToolTips>
                                            <ext:ToolTip Title="将当前页面内容存储为Excel文件">
                                            </ext:ToolTip>
                                        </ToolTips>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <ColumnModel ID="ColumnModel1" runat="server">
                            <Columns>
                                <ext:RowNumbererColumn Width="20" />
                                <ext:Column Header="用户ID" Sortable="true" Hidden="true" DataIndex="userid" />
                                <ext:Column Header="用户名" Sortable="true" DataIndex="username" />
                                <ext:Column Header="性别" Sortable="true" DataIndex="usersex" />
                                <ext:Column Header="电话" Sortable="true" DataIndex="telephone" />
                                <ext:Column Header="地址" Sortable="true" DataIndex="address" />
                                <ext:Column Header="邮箱" Sortable="true" DataIndex="email" />
                                <ext:Column Header="最后登录" Sortable="true" DataIndex="logintime" />
                                <ext:Column Header="创建时间" Sortable="true" DataIndex="createtime" />
                                <ext:Column Header="角色" Sortable="true" DataIndex="roleid">
                                    <Renderer Fn="GetRoleName" />
                                </ext:Column>
                            </Columns>
                        </ColumnModel>
                        <DirectEvents>
                            <RowDblClick OnEvent="GridDBClick">
                                <ExtraParams>
                                    <ext:Parameter Name="id" Value="#{GridPanel1}.store.getAt(rowIndex).get('userid')"
                                        Mode="Raw" />
                                </ExtraParams>
                            </RowDblClick>
                        </DirectEvents>
                        <LoadMask ShowMask="true" Msg="正在加载..." />
                        <SelectionModel>
                            <ext:CheckboxSelectionModel ID="CheckBoxGrid" runat="server" />
                        </SelectionModel>
                        <BottomBar>
                            <ext:PagingToolbar ID="PagingToolBar1" StoreID="Store1" PageSize="15" runat="server" />
                        </BottomBar>
                    </ext:GridPanel>
                </Items>
            </ext:FitLayout>
        </Items>
    </ext:Viewport>
    <ext:Window ID="WinUser" Collapsible="true" Hidden="true" Modal="true" TitleCollapse="true"
        Maximizable="false" runat="server" Title="添加/修改用户" Icon="User" Width="500" AutoHeight="true"
        Resizable="false">
        <Items>
            <ext:Hidden ID="Hid" runat="server">
            </ext:Hidden>
            <ext:FormPanel ID="RegistForm" LabelWidth="50" Frame="true" runat="server"
                Border="false" Height="100" ButtonAlign="Right" Icon="UserAdd" Layout="Column">
                <Items>
                    <ext:Panel ID="Panel1" runat="server" Border="false" Header="false" ColumnWidth=".5" Layout="Form">
                        <Items>
                            <ext:TextField ID="TxtUserName" AnchorHorizontal="92%" runat="server" AllowBlank="false"
                                EmptyText="该项不可为空" FieldLabel="用户名" />
                            <ext:TextField ID="TxtTel" AnchorHorizontal="92%" runat="server" AllowBlank="false"
                                EmptyText="该项不可为空" FieldLabel="电话" />
                            <ext:TextField ID="TxtAddress" AnchorHorizontal="92%" runat="server" AllowBlank="false"
                                EmptyText="该项不可为空" FieldLabel="地址" />
                        </Items>
                    </ext:Panel>
                    <ext:Panel ID="Panel2" runat="server" Border="false" Header="false" ColumnWidth=".5"
                        Layout="Form">
                        <Items>
                            <ext:ComboBox ID="cboSex" AnchorHorizontal="92%" FieldLabel="性别" Editable="false"
                                SelectedIndex="0" runat="server">
                                <Items>
                                    <ext:ListItem Text="男" />
                                    <ext:ListItem Text="女" />
                                </Items>
                            </ext:ComboBox>
                            <ext:TextField ID="TxtEmail" AnchorHorizontal="92%" runat="server" AllowBlank="false"
                                EmptyText="该项不可为空" FieldLabel="邮箱" Vtype="email" />
                            <ext:ComboBox ID="cboRole" AnchorHorizontal="92%" StoreID="S_Roles" runat="server"
                                FieldLabel="角色" TypeAhead="true" Editable="false" ForceSelection="true" DisplayField="rolename"
                                ValueField="roleid">
                            </ext:ComboBox>
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:FormPanel>
        </Items>
        <Buttons>
            <ext:Button Text="重置密码" ID="BtnResetPwd" runat="server" Icon="Key">
                <DirectEvents>
                    <Click OnEvent="BtnResetPwd_Click">
                        <EventMask ShowMask="true" Msg="正在重置密码，请等候 ..." />
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:Button Text="提交" ID="BtnSave" runat="server" Icon="Disk">
                <DirectEvents>
                    <Click OnEvent="BtnSave_Click">
                        <EventMask ShowMask="true" Msg="正在提交，请等候 ..."  />
                    </Click>
                </DirectEvents>
                <Listeners>
                    <Click Handler="if (#{RegistForm}.getForm().isValid()) {;}else{Ext.Msg.show({icon: Ext.MessageBox.ERROR, msg: '您填写的信息不正确，请您确认！', buttons:Ext.Msg.OK});return false;}" />
                </Listeners>
            </ext:Button>
            <ext:Button Text="取消" ID="Button6" runat="server" Icon="Delete">
                <Listeners>
                    <Click Handler="#{WinUser}.hide();" />
                </Listeners>
            </ext:Button>
        </Buttons>
    </ext:Window>
    </form>
</body>
</html>
